package LeetCode.LeetCode2;

/**
 * 环形链表
 * @author lumin
 * @date 2022/03/16 20:48
 **/
public class Num141 {
    class ListNode {
      int val;
      ListNode next;
      ListNode(int x) {
          val = x;next = null;
      }
   }
    public boolean hasCycle(ListNode head) {
        if(head == null || head.next == null){
            return false;
        }
        ListNode fast = head.next;
        ListNode low = head;
        while(fast != low){
            if(fast == null || fast.next == null){
                return false;
            }
            fast = fast.next.next;
            low = low.next;
        }
        return true;
    }
}